#include "atch_tcp.h"
#include "atch_udp.h"
#include "util.h"
unsigned int x1;
unsigned int x2;

void send_tcp_msg(TcpClientSession *tcs)
{
    while (true)
    {
        unsigned char x = 0;
        unsigned char y = 0;
        int input = util_get_char();
        switch (input)
        {
        case 1000:
            x = 0x01;
            y = x1 = util_clamp(++x1, 0, 90);
            break;
        case 1001:
            x = 0x01;
            y = x1 = util_clamp(--x1, 0, 90);
            break;
        case 1002:
            x = 0x00;
            y = x2 = util_clamp(++x2, 0, 90);
            break;
        case 1003:
            x = 0x00;
            y = x2 = util_clamp(--x2, 0, 90);
            break;
        default:
            // printf("cant find this key : %d\n", input);
            usleep(5 * 1000);
            continue;
            break;
        }
        printf("the angle is  %d\n", y);
        char msg[5] = {
            0xff,
            0x02,
            x,
            y,
            0xff};
        tcp_client_session_sendmsg(tcs, msg, 5);
        usleep(5 * 1000);
    }
}
int main(int argc, const char *argv[])
{
    create_tcp_client_session("14.103.165.128", 20001, NULL, send_tcp_msg);
    sleep(600);
    return 0;
}
